package demo;

public class Solution {
    public TreeNode invertTree(TreeNode root) {
        //先将左子树与右子树翻转
        //再将左子树变成右子树
        //右子树变成左子树
        if (root == null) {
            return root;
        }
        TreeNode leftResult = invertTree(root.left);
        TreeNode rightResult = invertTree(root.right);

        root.left = rightResult;
        root.right = leftResult;

        return root;
    }
}
